package vip.xiaonuo.supplier.modular.base.units.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.supplier.modular.base.units.entity.SupplierUnits;
import vip.xiaonuo.supplier.modular.base.units.param.SupplierUnitsAddParam;
import vip.xiaonuo.supplier.modular.base.units.param.SupplierUnitsEditParam;
import vip.xiaonuo.supplier.modular.base.units.param.SupplierUnitsIdParam;
import vip.xiaonuo.supplier.modular.base.units.param.SupplierUnitsPageParam;
import vip.xiaonuo.supplier.modular.base.units.service.SupplierUnitsService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 单位控制器
 *
 * @author Mr.wu
 * @date  2025/02/28 21:16
 */
@Tag(name = "单位控制器")
@RestController
@Validated
public class SupplierUnitsController {

    @Resource
    private SupplierUnitsService supplierUnitsService;

    /**
     * 获取单位分页
     *
     * @author Mr.wu
     * @date  2025/02/28 21:16
     */
    @Operation(summary = "获取单位分页")
    @SaCheckPermission("/supplier/base/units/page")
    @GetMapping("/supplier/base/units/page")
    public CommonResult<Page<SupplierUnits>> page(SupplierUnitsPageParam supplierUnitsPageParam) {
        return CommonResult.data(supplierUnitsService.page(supplierUnitsPageParam));
    }

    /**
     * 添加单位
     *
     * @author Mr.wu
     * @date  2025/02/28 21:16
     */
    @Operation(summary = "添加单位")
    @CommonLog("添加单位")
    @SaCheckPermission("/supplier/base/units/add")
    @PostMapping("/supplier/base/units/add")
    public CommonResult<String> add(@RequestBody @Valid SupplierUnitsAddParam supplierUnitsAddParam) {
        supplierUnitsService.add(supplierUnitsAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑单位
     *
     * @author Mr.wu
     * @date  2025/02/28 21:16
     */
    @Operation(summary = "编辑单位")
    @CommonLog("编辑单位")
    @SaCheckPermission("/supplier/base/units/edit")
    @PostMapping("/supplier/base/units/edit")
    public CommonResult<String> edit(@RequestBody @Valid SupplierUnitsEditParam supplierUnitsEditParam) {
        supplierUnitsService.edit(supplierUnitsEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除单位
     *
     * @author Mr.wu
     * @date  2025/02/28 21:16
     */
    @Operation(summary = "删除单位")
    @CommonLog("删除单位")
    @SaCheckPermission("/supplier/base/units/delete")
    @PostMapping("/supplier/base/units/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<SupplierUnitsIdParam> supplierUnitsIdParamList) {
        supplierUnitsService.delete(supplierUnitsIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取单位详情
     *
     * @author Mr.wu
     * @date  2025/02/28 21:16
     */
    @Operation(summary = "获取单位详情")
    @SaCheckPermission("/supplier/base/units/detail")
    @GetMapping("/supplier/base/units/detail")
    public CommonResult<SupplierUnits> detail(@Valid SupplierUnitsIdParam supplierUnitsIdParam) {
        return CommonResult.data(supplierUnitsService.detail(supplierUnitsIdParam));
    }
}
